home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_05 / allison / date5.cpp < prev    next >
C/C++ Source or Header  |  1995-03-12  |  776b  |  34 lines

  1. LISTING 13 - Adds a stream inserter to the Date class
  2. implementation
  3. // date5.cpp
  4.  
  5. #include <iostream.h>
  6. #include "date3.h"
  7.  
  8. const char * Date::month_text[13] =
  9.     {"Bad month", "January", "February", "March", "April",
  10.      "May", "June", "July", "August", "September",
  11.      "October", "November", "December"};
  12.  
  13. Date::Date(int m, int d, int y) : month(m), day(d), year(y)
  14. {}
  15.  
  16. ostream & operator<<(ostream & os, const Date &d)
  17. {
  18.     os << Date::month_text[d.month]
  19.        << ' ' << d.day
  20.        << ", " << d.year;
  21.     return os;
  22. }
  23.  
  24. int Date::compare(const Date & dp2) const
  25. {
  26.     int result = year - dp2.year;
  27.     if (result == 0)
  28.         result = month - dp2.month;
  29.     if (result == 0)
  30.         result = day - dp2.day;
  31.     return result;
  32. }
  33.  
  34.